package com.learning.springboot.springdataJpa.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * Created by td on 2017/9/15.
 */
@Configuration
@ConditionalOnClass(com.alibaba.druid.pool.DruidDataSource.class)
public class DruidDataSourceAutoConfigure {


    @ConfigurationProperties("spring.datasource.druid")
    @ConditionalOnMissingBean
    @Bean
    public DataSource dataSource(Environment environment) {

        DataSource dataSource = DruidDataSourceBuilder.create().build();

        System.out.println("111111");

        System.out.println(dataSource.toString());

        return dataSource;
    }


}
